#include <stdio.h>
#include <stdlib.h>

// 双向循环链表
typedef struct node
{
    int data;
    struct node *print;
    struct node *next;
} Dlink;

//初始化一个双向链表
Dlink *initDlink(int length)
{
    // 申请头结点
    Dlink *header = (Dlink *)malloc(sizeof(Dlink));
    header->data = 0;

    Dlink *top = header;

    for (int i = 1; i < length; i++)
    {
        // 申请一个新节点
        Dlink *item = (Dlink *)malloc(sizeof(Dlink));
        item->data = i;
        item->print = top;

        top->next = item;
        top = item;

        printf("init value=%d \n", i);
    }
    top->next = header;
    header->print = top;

    return header;
}
// 打印一个双向循环链表
void printDLink(Dlink *header)
{
    Dlink *item = header->next;
    
    while (item != header)
    {
        printf("print val=%d \n", item->data);
        item = item->next;
    }
}

void main()
{
    Dlink *item = initDlink(5);
    printDLink(item);
}